//请实现一个函数，把字符串 s 中的每个空格替换成"%20"。 
//
// 
//
// 示例 1： 
//
// 输入：s = "We are happy."
//输出："We%20are%20happy." 
//
// 
//
// 限制： 
//
// 0 <= s 的长度 <= 10000 
// 👍 49 👎 0


//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String replaceSpace(String s) {
        if ("".equals(s) || s.length()==0){
            return "";
        }
        int originLength = s.length();
        char[] array = new char[originLength];
        int count=0;
        for (int i = 0; i < originLength; i++) {
            if (s.charAt(i) == ' '){
                count++;
            }
            array[i] = s.charAt(i);
        }
        int newArrayLength = s.length() + count*2;
        char[] newArray = new char[newArrayLength];
        newArrayLength = newArrayLength-1;
        for (int i = array.length - 1; i >= 0; i--) {
            if (array[i] == ' '){
                newArray[newArrayLength--] = '0';
                newArray[newArrayLength--] = '2';
                newArray[newArrayLength--] = '%';
            }else{
                newArray[newArrayLength--] = array[i];
            }
        }
        return String.valueOf(newArray);
    }
}
//leetcode submit region end(Prohibit modification and deletion)
